package neuroBot.exploit.party;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class PPWindowTitleReader {
	public int getTableNr(int tnr) {
		String title = readTitle(tnr);
		String tableNrStr = title.substring(7, 13);
		int tableNr = Integer.parseInt(tableNrStr);
		return tableNr;
	}

	public String readTitle(int tnr) {
		String s = null;
		for (int i = 0; s == null; i++) {
			if (i > 0) {
				new ScreenShooter().shoot("FailedReadTitle" + tnr, 0, 0, 1280,
						1024);
				System.out
						.println("PPWinTitleReader: Failed to read title for TNR: "
								+ tnr + "-> Trying again");
			}
			try {
				Process p = Runtime.getRuntime().exec(
						new String[] { "pphandler.exe", "TITLE", "" + tnr });
				InputStream is = p.getInputStream();
				InputStreamReader isr = new InputStreamReader(is);
				BufferedReader br = new BufferedReader(isr);
				s = br.readLine();
				p.waitFor();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return s;
	}
}
